var DocData={
    billingURL:'/xrtn-manager/order/gotoFastOrder',
    baseTimeDay:86400000,
    baseWeek:0,
    sendBooking:false,
    timecompat:function(time){
        var curDate=new Date(),curTime=curDate.getTime(),baseTimeDay=this.baseTimeDay,weekbase=curDate.getDay();
        var _weekStart = curTime-((weekbase-1)*baseTimeDay);
        var _weekEnd = curTime+((7-weekbase)*baseTimeDay);
        _weekStart = _weekStart+(baseTimeDay*7*this.baseWeek);
        _weekEnd = _weekEnd+(baseTimeDay*7*this.baseWeek);
        var _weekStartStr = baseFn.timestampToTime(_weekStart).substring(0,10);
        var _weekEndStr = baseFn.timestampToTime(_weekEnd).substring(0,10);
        // $("#startDate_stat").val(_weekStartStr);
        // $("#endDate_stat").val(_weekEndStr);
        return {
            weekStart:_weekStartStr,
            weekEnd:_weekEndStr
        }
    },
    initAddBespeak:function(data){//新增/编辑预约的弹窗
        $('.js_noUserWrap').addClass('hidden')
        var _opts = $.extend({},{
            edit:false,
            bookingId:'',
            userId:'',
            userPhone:'',
            userPhones:'',
            bookingTime:'',
            userName:'',
            doctorId:"",
            subclinicId:'',
            bookingDesc:'',

        },data || {})
        $("#searchbox").val(null).trigger('change');
        $('.js_searchvip_wrap').removeClass('hidden')
        $('.addBespeak').find('input[name="bookingId"]').val(_opts.bookingId)
        $('.addBespeak').find('input[name="userPhone"]').val(_opts.userPhone).prop('disabled',_opts.edit)
        $('.addBespeak').find('input[name="userPhones"]').val(_opts.userPhones).prop('disabled',_opts.edit)
        $('.addBespeak').find('input[name="userName"]').val(_opts.userName).prop('disabled',_opts.edit)
        $('.addBespeak').find('input[name="bookingTime"]').val(_opts.bookingTime)
        $('.addBespeak').find('textarea[name="bookingDesc"]').val(_opts.bookingDesc)
        var _upData_ = {}
        if(_opts.subclinicId != ''){
            $('.addBespeak').find('select[name="subclinicId"]').val(_opts.subclinicId).trigger('change')
            _upData_.subclinicId=_opts.subclinicId
        }
        $('.addBespeak').find('select[name="doctorId"]').val(_opts.doctorId)
        if(baseFn.notNull(_opts.bookingTime)){
            _upData_.bookingTime = _opts.bookingTime +':00'
        }
        selectDoctor(_upData_)

        if(_opts.edit){
            $('.addBespeak').removeClass('hidden');
            $('.sureBtn').addClass('hidden');
            $('.add').addClass('hidden');
            $('.save').removeClass('hidden');
            $('.saveBtn').removeClass('hidden');
            $('.js_searchvip_wrap').addClass('hidden')
            $('.js_patientwrap').removeClass('hidden')
        }else{
            $('.js_searchvip_wrap').removeClass('hidden')
            $('.js_patientwrap').addClass('hidden')
            $('.addBespeak').removeClass('hidden');
            $('.sureBtn').removeClass('hidden');
            $('.add').removeClass('hidden');
            $('.save').addClass('hidden');
            $('.saveBtn').addClass('hidden');
        }

    },
    renderPatient:function(data){
        //新增预约 渲染宝宝及相关数据按钮的操作
        var _data= data,that=this;
        var _default = {
            createTime:'',
            patientAddress:'',
            patientAge:0,
            patientBirthday:'',
            patientBodyWeight:0,
            patientCard:null,
            patientDesc:"",
            patientGender:'',
            patientHeight:0,
            patientId:'',
            patientImg:"",
            patientName:"",
            patientPhone:null,
            userId:'',
            lastTime:'',
            bookingType:1,
            isAdd:1,
        }
        var _opts= $.extend({},_default,(_data ||{}))
        if(baseFn.notNull(_opts.patientId)){
            $('.js_patientBirthdayWrap').addClass('hidden')
            $('.js_patientAgeWrap').removeClass('hidden')
        }else{
            $('.js_patientBirthdayWrap').removeClass('hidden')
            $('.js_patientAgeWrap').addClass('hidden')
        }
        $('.js_tipsbtn').removeClass('active')
        $('.js_tipsbtn').off('click').on('click',function(){
            if($(this).hasClass('disabled')){
                return false;
            }
            $(this).addClass('active')
            if($(this).attr('rel') == 1){
                $('.js_tipsbtn[rel=2]').removeClass('active')
                that.bookingInfo.bookingType = 0
                $('.js_tips2_wrap').removeClass('hidden');
                if(_opts.bookingType == 0){
                    $('.js_tipsbtn[rel=3]').removeClass('disabled');
                    that.bookingInfo.isAdd = 0
                }else{
                    $('.js_tipsbtn[rel=3]').addClass('disabled')
                    that.bookingInfo.isAdd = 1
                    $('.js_tipsbtn[rel=4]').addClass('active')
                }
            }else if($(this).attr('rel') == 2){
                $('.js_tipsbtn[rel=1]').removeClass('active')
                $('.js_tips2_wrap').addClass('hidden')
                that.bookingInfo.bookingType = 1
                that.bookingInfo.isAdd = 1
            }else if($(this).attr('rel') == 3){
                $('.js_tipsbtn[rel=4]').removeClass('active')
                that.bookingInfo.isAdd = 0
            }else if($(this).attr('rel') == 4){
                $('.js_tipsbtn[rel=3]').removeClass('active')
                that.bookingInfo.isAdd = 1
            }
        })
        if(baseFn.notNull(that.bookingInfo.patientId) && that.bookingInfo.patientId == _opts.patientId){
            if(baseFn.notNull(that.bookingInfo.bookingType)){
                $('.js_tipsbtn[rel='+(Number(that.bookingInfo.bookingType)+1)+']').addClass('active')
            }
            if(baseFn.notNull(that.bookingInfo.isAdd)){
                $('.js_tipsbtn[rel='+(Number(that.bookingInfo.isAdd)+3)+']').addClass('active')
            }
        }else{
            that.bookingInfo.patientId = _opts.patientId
            $('.js_tipsbtn[rel=2]').addClass('active');
            $('.js_tipsbtn[rel=3]').addClass('active');
            $('.js_tips2_wrap').addClass('hidden');
            that.bookingInfo.isAdd = 1
            that.bookingInfo.bookingType = 1
        }
        if(baseFn.notNull(_opts.patientId)){
            $('.js_patientInfo .js_patientName').val(_opts.patientName).addClass('border_no').prop('disabled','true')
            $('.js_patientInfo .js_patientAge').val(_opts.patientAge).addClass('border_no').prop('disabled','true')
            $('.js_patientInfo .js_gender').val(baseFn.notNull(_opts.patientGender)?_opts.patientGender:0).addClass('border_no').prop('disabled','true')
            if(baseFn.notNull(_opts.lastTime)){
                $('.js_patientInfo .js_lastTime').text(baseFn.timestampToTime(_opts.lastTime))
            }else{
                $('.js_patientInfo .js_lastTime').text('最近没有就诊～')
            }
        }else{
            $('.js_patientInfo .js_patientName').val(_opts.patientName).removeClass('border_no').prop('disabled',false)
            $('.js_patientInfo .js_patientAge').val(_opts.patientAge).removeClass('border_no').prop('disabled',false)
            $('.js_patientInfo .js_gender').val(baseFn.notNull(_opts.patientGender)?_opts.patientGender:0).removeClass('border_no').prop('disabled',false)
            $('.js_patientInfo .js_lastTime_wrap').addClass('hidden')
            $('.js_tips2_wrap').addClass('hidden')
        }


    },
    //预约详情
    startTimeD:baseFn.getQueryString('startTime',true),
    endTimeD:baseFn.getQueryString('endTime',true),
    bookingStatusD:baseFn.getQueryString('bookingStatus',true),
    bookingTypeD:baseFn.getQueryString('bookingType',true),
    subclinicId:baseFn.getQueryString('subclinicId',true),
    userPhoneD:baseFn.getQueryString('userPhone',true),
    bookingInfo:{
        doctorId:'',
        subclinicId:baseFn.getQueryString('subclinicId',true),
        patientId:'',
        bookingType:'',
        isAdd:''
    },
    maxDate:false,
    subclinicList:[],
    bookingTime:{
        timepicker: true,    //开启时间选项
        yearStart: 2000,//设置最小年份
        minDate: 0,
        yearEnd: 2050,        //设置最大年份
        allowTimes: ['09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00','21:00','22:00','23:00'],
        maxDate:false,
        onSelectDate:function(){},
        onSelectTime:function(){
            var _val = $('.js_subclinicId').val()
            if(baseFn.notNull(_val)){
                var _datas={
                    subclinicId:$('.js_subclinicId').val(),
                    bookingTime:_val
                }
                selectDoctor(_datas)
            }
        }
    }
}
baseFn.getOSTime=function(time){
    return time.replace(/\-/g, "/")
}
$('.bespeak_change_look tbody').css('max-height',windowOffsetData.mainWraperHeight-110)
/*新增预约*/
//时间初始化
baseFn.dateTimePick('.js_bookingTime',DocData.bookingTime)
//宝宝信息
baseFn.dateTimePick('.js_patientBirthday',{})
//添加预约-保存
/*
$('.sureBtn').click(function () {
    var userId = 1;
    var userPhone = $('#userPhone').val();
    var userPhones = $('#userPhones').val();
    var userName = $('#userName').val();
    //var userGender = $('input:radio:checked').val();
    var bookingTime = $('#bookingTime').val();
    var subclinicId = $('.js_subclinicId').val();
    var doctorId = $('.js_doctorId').val();
    var bookingDesc = $('#bookingDesc').val();

    //验证
    if (userPhone == '') {
        $('#flag1').html("<span class='zcerror' style='color: red;font-size: 8px;'>手机号非空</span>");
        return;
    }
    if(!/^13[0-9]{9}$|14[0-9]{9}|17[0-9]{9}|15[0-9]{9}$|18[0-9]{9}$/.test(userPhone)){
        $('#flag1').html("<span class='zcerror' style='color: red;font-size: 8px;'>手机号格式不正确</span>");
        return;
    }
    if (userName == '') {
        $('#flag1').addClass('hidden');
        $('#flag2').html("<span class='zcerror' style='color: red;font-size: 8px;'>预约人非空</span>");
        return;
    }
    if (bookingTime == '') {
        $('#flag2').addClass('hidden');
        $('#flag4').html("<span class='zcerror' style='color: red;font-size: 8px;'>时间非空</span>");
        return;
    }else{
        bookingTime = bookingTime+':00'
    }
    if (subclinicId == '') {
        $('#flag4').addClass('hidden');
        $('#flag5').html("<span class='zcerror' style='color: red;font-size: 8px;'>推拿师非空</span>");
        return;
    }
    if (doctorId == '') {
        $('#flag4').addClass('hidden');
        $('#flag5').html("<span class='zcerror' style='color: red;font-size: 8px;'>请选择推拿师</span>");
    }
    $('#flag5').addClass('hidden');
    bookingTime = bookingTime + ':00';
    var _upDatas = {
        "userPhone": userPhone,
        "userPhones": userPhones,
        "userName": userName,
        "bookingTime": bookingTime,
        "subclinicId": subclinicId,
        "doctorId": doctorId,
        "bookingDesc": bookingDesc
    }
    if(baseFn.notNull(DocData.bookingInfo.patientId)){
        _upDatas.patientId = DocData.bookingInfo.patientId
    }else{
        _upDatas.patientName = $('input.js_patientName').val()
        _upDatas.patientGender = $('select.js_gender').val()
        _upDatas.patientBirthday = $('input.js_patientBirthday').val()
    }
    if(baseFn.notNull(DocData.bookingInfo.bookingType)){
        _upDatas.bookingType = DocData.bookingInfo.bookingType
    }
    if(baseFn.notNull(DocData.bookingInfo.isAdd)){
        _upDatas.isAdd = DocData.bookingInfo.isAdd
    }
    // console.log(_upDatas)
    // return false
    if(DocData.sendBooking){
        baseFn.infoDialog('预约正在提交中，不要重复操作');
        return false
    }
    DocData.sendBooking=true
    $.ajax({
        type: "POST",
        url: baseUrl.base + "booking/saveBooking",
        data:_upDatas,
        success: function (res) {
            if (res.code == 0) {
                var _results = res.results
                baseFn.dialog({
                    content: '提交成功,是否前往开单继续操作？',
                    okValue: '前往',
                    ok: function () {
                        window.location.href = DocData.billingURL + '?bookingId=' + _results.bookingId + '&userId=' + _results.userId + '&doctorId=' + _results.doctorId + '&subclinicId=' + _results.subclinicId
                    },
                    cancel: function () {
                    }
                })
                $('.addBespeak').addClass('hidden');
                bookerDT.ajax.reload();
                if ($('#day1').hasClass("addBlueActive")) {
                    $('#day1').click();// 今天
                } else if ($('#day2').hasClass("addBlueActive")) {
                    $('#day2').click();// 明天
                } else if ($('#day3').hasClass("addBlueActive")) {
                    $('#day3').click(); // 后天
                }
            }else{
                baseFn.infoDialog(res.msg)
            }
            DocData.bookingInfo={}

        },
        complete:function(){
            DocData.sendBooking=false
        }
    });
});
*/
//编辑预约-编辑
$('.saveBtn').click(function () {
    var userPhone = $('#userPhone').val();
    var userPhones = $('#userPhones').val();
    var userName = $('#userName').val();
    var bookingTime = $('#bookingTime').val();
    var subclinicId = $('.js_subclinicId').val();
    var doctorId = $('.js_doctorId').val();
    var bookingDesc = $('#bookingDesc').val();
    var bookingId = $('#bookingId').val();
    // alert(bookingId);
    //验证
    if (userPhone == '') {
        $('#flag1').html("<span class='zcerror' style='color: red;font-size: 8px;'>手机号非空</span>");
        return;
    }
    if(!/^13[0-9]{9}$|14[0-9]{9}|17[0-9]{9}|15[0-9]{9}$|18[0-9]{9}$/.test(userPhone)){
        $('#flag1').html("<span class='zcerror' style='color: red;font-size: 8px;'>手机号格式不正确</span>");
        return;
    }
    if (userName == '') {
        $('#flag1').addClass('hidden');
        $('#flag2').html("<span class='zcerror' style='color: red;font-size: 8px;'>预约人非空</span>");
        return;
    }
    if (bookingTime == '') {
        $('#flag2').addClass('hidden');
        $('#flag4').html("<span class='zcerror' style='color: red;font-size: 8px;'>时间非空</span>");
        return;
    }else{
        bookingTime = bookingTime+':00'
    }
    if (subclinicId == '') {
        $('#flag4').addClass('hidden');
        $('#flag5').html("<span class='zcerror' style='color: red;font-size: 8px;'>推拿师非空</span>");
        return;
    }
    if (doctorId == '') {
        $('#flag4').addClass('hidden');
        $('#flag5').html("<span class='zcerror' style='color: red;font-size: 8px;'>请选择推拿师</span>");
    }
    $('#flag5').addClass('hidden');
    $.ajax({
        type: "POST",
        url: baseUrl.base + "booking/updateBooking",
        data: {
            "userPhone": userPhone,
            "userName": userName,
            "bookingTime": bookingTime,
            "subclinicId": subclinicId,
            "doctorId": doctorId,
            "bookingDesc": bookingDesc,
            "bookingId": bookingId,
            "patientId":DocData.bookingInfo.patientId,
            "bookingType":DocData.bookingInfo.bookingType,
            "isAdd":baseFn.notNull(DocData.bookingInfo.isAdd)?DocData.bookingInfo.isAdd:1
        },
        success: function (result) {
            if (result.code == 0) {
                var _results = {
                    bookingId:bookingId,
                    userPhone:userPhone,
                    doctorId:doctorId,
                    subclinicId:subclinicId
                }
                baseFn.dialog({
                    content:'更新成功',
                    okValue:'确定',
                    ok:function(){
                        // window.location.href = DocData.billingURL+'?bookingId='+_results.bookingId+'&doctorId='+_results.doctorId+'&subclinicId='+_results.subclinicId+'&userPhone='+_results.userPhone
                    }
                })

                $('.addBespeak').addClass('hidden');
                bookerDT.ajax.reload(null,false);
                DocData.bookingInfo={}

            }
        }
    });
});
//添加预约-按钮
$('.Baby_Healthy_home_right').on('click','.js_addbespeak', function () {
    //预约看板 有预约时间 门店 推拿师 新增按钮进入都没有
    var beskData={}
    if(baseFn.notNull($(this).attr('value'))){
        beskData.bookingTime=$(this).attr('value')+':00'
    }
    if($(this).data('info')){
        beskData.doctorId=$(this).data('info').split(',')[1],
        beskData.subclinicId=$(this).data('info').split(',')[0]
    }
    baseFn.goPath('gotoBooking',beskData)
});
// 关闭弹窗
$('.addBespeak_tit_close,.saveBespeak_tit_close').on('click', function () {
    $('.addBespeak').addClass('hidden');
    $('.zcerror').remove();
    $('.js_patientwrap').addClass('hidden');
});

// 搜索用户
$('#searchbox').select2({
    placeholder: '请输入手机号或姓名',
    allowClear: true,
    tags: true,
    ajax: {
        url: baseUrl.base+"user/selectUserList",
        type: "get",
        dataType: 'json',
        data: function (params) {
            return {
                userPhone: params.term
            }
        },
        processResults: function (data) {
            var dataResult =[];
            var dataItem = data.results.rows;
            for(var i=0;i<dataItem.length;i++){
                var resultObj = {id:'',text:''};
                resultObj['text'] = dataItem[i].userName + '-' +dataItem[i].userPhone;
                // resultObj['id'] = dataItem[i].userName + '-' +dataItem[i].userPhone + '-' + dataItem[i].userId;
                resultObj['id'] = dataItem[i].userPhone;
                dataResult.push(resultObj);
            }
            if(dataResult.length>0){
                $('#select2-searchbox-results').find('li').eq(0).addClass('hidden')
            }
            return {
                results:dataResult,
            }
        },
        formatResult: function formatRepo(repo){return repo.text;}, // 函数用来渲染结果
        formatSelection: function formatRepoSelection(repo){return repo.text;} // 函数用于呈现当前的选择
    },
    escapeMarkup: function (markup) {return markup; }, // 自定义格式化防止xss注入
    minimumInputLength: function(e){
        var _val = e.term;
        if(/^[\u4e00-\u9fa5]{1,5}$/.test(_val)){
            return 1
        }else{
            return 3
        }
    }//最少输入多少个字符后开始查询
});
$("#searchbox").on("select2:select",function(){
    // var res = $(this).val().split("-");
    // $('.js_patientwrap').removeClass('hidden');
    DocData.bookingInfo.patientId = ''
    var _val=$(this).val()
    // if (res.length < 2) {
    //     $("#userPhone").val('');
    //     $("#userName").val('');
    //     // initPatientListFn({userId:''})
    //     $('.js_noUserWrap').removeClass('hidden')
    //     return;
    // }
    // var name = res[0];
    // var phone = res[1];
    baseFn.$get({
        url:"user/selectUserList",
        data:{userPhone:_val},
        canNull:true,
        calFn:function(res){
            var _data = res.rows;
            if(_data && _data.length > 0){
                $("#userPhone").val(_data[0].userPhone);
                $("#userName").val(_data[0].userName);
                initPatientListFn({userId:_data[0].userId})
                $('.js_noUserWrap').addClass('hidden')
                $('.js_patientwrap').removeClass('hidden')
            }else{
                $('.js_noUserWrap').removeClass('hidden')
                initPatientListFn({userId:''});
            }
        }
    })

})
//修改预约中宝宝列表渲染函数      
function initPatientListFn(data){
    DocData.patientListData=[];
    $('.js_patientwrap .patientlist').html('')
    if(baseFn.notNull(data.userId)){
        baseFn.$get({
            url:'patient/selectPatientInfoList',
            data: {"userId": data.userId},
            canNull:true,
            calFn:function(res){
                if(res && baseFn.isArray(res) && res.length > 0){
                    //会员身下有宝宝
                    DocData.patientListData=res;
                    var _html=''
                    if(res.length > 0){
                        $('.js_patientwrap').removeClass('hidden')
                    }
                    for(var i =0;i<res.length;i++){
                        DocData.patientListData[i].ids = i
                        _html += '<p class="patientelm" rel="'+i+'">'+res[i].patientName+'</p>'
                    }
                    $('.js_patientwrap .patientlist').append(_html)
                    $('.js_patientwrap .patientlist').find('.patientelm').off('click').on('click',function(){
                        var $this = $(this)
                        $this.addClass('active').siblings('.patientelm').removeClass('active');
                        DocData.renderPatient(DocData.patientListData[$this.attr('rel')])
                    })
                    if(baseFn.notNull(DocData.bookingInfo.patientId)){
                        var _patientInfo = DocData.patientListData.filter(function(val){
                            return val.patientId == DocData.bookingInfo.patientId
                        })[0]
                        DocData.renderPatient(_patientInfo)
                        $('.js_patientwrap .patientlist').find('.patientelm[rel='+_patientInfo.ids+']').addClass('active')
                    }else{
                        $($('.js_patientwrap .patientlist').find('.patientelm')[0]).addClass('active')
                        DocData.renderPatient(DocData.patientListData[0])
                    }
                }else{
                    DocData.renderPatient()
                    //会员身下无宝宝
                }
            }
        })
    }else{
        DocData.renderPatient()
        //新会员且身下无宝宝
    }
}
/*新增预约*/
/*预约列表 */
//预约列表条件初始化
var bookerDT = ''
var subclinicIds = baseFn.getQueryString('subclinicId',true);
var flag = baseFn.getQueryString('flag',true);
if(flag == 2) {
    $.session.remove('bespeak_tab');
    $.session.remove('bespeak_change_list_actve');
    $.session.remove('bespeak_change_list_datas');
    $('li[rel="0"]').removeClass("active_bgc");
    $('li[rel="3"]').addClass("active_bgc");
}else if(flag == 1){
    $.session.remove('bespeak_tab');
    $.session.remove('bespeak_change_list_actve');
    $.session.remove('bespeak_change_list_datas');
    bespeak_change_active($('.bespeak_change_list_actve0'));
}else {
    if (baseFn.notNull($.session.get('bespeak_change_list_actve'))){
        bespeak_change_active($($.session.get('bespeak_change_list_actve')));
    }else {
        bespeak_change_active($('.bespeak_change_list_actve0'));
    }
}

var bookerDTdata={
    limit:10,
    startDate:function(){
        if (baseFn.notNull($.session.get('bespeak_change_list_datas'))){
            var data = JSON.parse($.session.get('bespeak_change_list_datas'));
            if (baseFn.notNull(data.startDate)){
                return data.startDate;
            }
        }
        return getNowFormatDate();
    },
    endDate:function(){
        if (baseFn.notNull($.session.get('bespeak_change_list_datas'))){
            var data = JSON.parse($.session.get('bespeak_change_list_datas'));
            if (baseFn.notNull(data.endDate)){
                return data.endDate;
            }
        }
        return getNowFormatDate();
    },
    subclinicId:function(){
        if (baseFn.notNull($.session.get('bespeak_change_list_datas'))){
            var data = JSON.parse($.session.get('bespeak_change_list_datas'));
            if (baseFn.notNull(data.subclinicId)){
                return data.subclinicId;
            }
        }
        return SessionData.powerSub?SessionData.powerSub:0;
    },
    bookingStatus:function(){
        if (baseFn.notNull($.session.get('bespeak_change_list_datas'))){
            var data = JSON.parse($.session.get('bespeak_change_list_datas'));
            if (baseFn.notNull(data.bookingStatus)){
                return data.bookingStatus;
            }
        }
        return $('.bespeak_change_list .active_bgc').attr('rel') ? $('.bespeak_change_list .active_bgc').attr('rel') : 0;
    },
    bookingType:function () {
        if (baseFn.notNull($.session.get('bespeak_change_list_datas'))){
            var data = JSON.parse($.session.get('bespeak_change_list_datas'));
            if (baseFn.notNull(data.bookingType)){
                return data.bookingType;
            }
        }
        return '';
    },
    userPhone:function () {
        if (baseFn.notNull($.session.get('bespeak_change_list_datas'))){
            var data = JSON.parse($.session.get('bespeak_change_list_datas'));
            if (baseFn.notNull(data.userPhone)){
                return data.userPhone;
            }
        }
        return '';
    }
}//预约单列表data数据


// bookingListDTFn()
// 获取预约列表基础数据及查询数据
function getListDatas(){

    var datas = {};
    var startDate = $('#startDate').val();
    var endDate = $('#endDate').val();
    var subclinicId = SessionData.powerSub?SessionData.powerSub:$('#subclinic option:selected').val();//权限管理 45 全部门店

    var userPhone = $('.list_search').siblings('input.bespeak_search_input').val();
    var bookingStatus = $('.bespeak_change_list .active_bgc').attr('rel');
    var bookingType = $('.js_bookingtype').val();
    if(startDate != '')
    {
        datas.startDate = startDate;
    }
    if(endDate != '')
    {
        datas.endDate = endDate;
    }
    if(subclinicId != '' && subclinicId != ' ')
    {
        datas.subclinicId = subclinicId;
    }
    if(userPhone != '')
    {
        datas.userPhone = userPhone;
    }
    if(bookingStatus != '')
    {
        datas.bookingStatus = bookingStatus;
    }
    if(bookingType !=''){
        datas.bookingType = bookingType;
    }

    $.session.set('bespeak_change_list_datas',JSON.stringify(datas));

    return datas;
}

//预约列表筛选条件初始化
if (baseFn.notNull($.session.get('bespeak_change_list_datas'))){
    var data = JSON.parse($.session.get('bespeak_change_list_datas'));
    $('#startDate').val(data.startDate);
    $('#endDate').val(data.endDate);
    $('.list_search').siblings('input.bespeak_search_input').val(data.userPhone);
    $('.js_bookingtype').val(data.bookingType);
}else {
    $('#startDate').val(bookerDTdata.startDate);
    $('#endDate').val(bookerDTdata.endDate);
}

//预约看板筛选条件初始化
if (baseFn.notNull($.session.get('selectDoctorGroupBookingList'))){
    var data = JSON.parse($.session.get('selectDoctorGroupBookingList'));
    $('.js_kbsearch_type').val(data.bookingType);
    if (baseFn.notNull(data.bookingDate)){
        $('#bespeak_change_time').val(data.bookingDate);
        $('.bespeak_change_look_li').removeClass('addBlueActive');
    }
}

//预约信息筛选条件初始化
if (baseFn.notNull($.session.get('selectBookingWeekList'))){
    var data = JSON.parse($.session.get('selectBookingWeekList'));
    $('.bespeak_search_input').val(data.userPhone);
    $('#status_info').val(data.bookingType);
}

//预约列表-时间筛选初始化
baseFn.dateTimePickGroup('.selDatebeskpeck', {
    startseled: function () {
        bookingListDTFn()
    },
    endseled: function () {
        bookingListDTFn()
    },
    maxDate:false
})

//预约统计信息-时间筛选初始化
baseFn.dateTimePickGroup('.selDateStat', {
    startseled: function () {
        getbesInfoDatas(false, true)
    },
    endseled: function () {
        getbesInfoDatas(false, true)
    },
    maxDate:false
})

//预约列表 tab切换
$('.bespeak_change_list_actve').on('click', function () {
    bespeak_change_active($(this));
    bookingListDTFn();
})



function bespeak_change_active(ev){
    var thisIndex = ev.index();
    $.session.set('bespeak_change_list_actve','.bespeak_change_list_actve' + thisIndex);
    ev.addClass("active_bgc").siblings().removeClass("active_bgc");
    $('.bespeak_change_table').eq(thisIndex).show().siblings(".bespeak_change_table").hide();
}

//搜索(搜索到内容没进行处理)
$('.list_search').on('click',function () {
    bookingListDTFn()
});

$("#search").keydown(function(event) {
    if (event.keyCode == "13") {
        bookingListDTFn()
    }
});

$('.js_bookingtype').on('change',function(){
    bookingListDTFn()
})
$('.js_out_besk_btn').on('click',function(){
    var _data = getListDatas();
    var updata={
        startDate: _data.startDate,
        endDate: _data.endDate,
        bookingStatus: _data.bookingStatus
    }
    updata={}
    if(_data.subclinicId != 0){
        updata.subclinicId=_data.subclinicId
    }
    $(this).attr('href',baseFn.goPath('exportBookingList',updata,'urlData'))
})
//预约列表渲染函数
function bookingListDTFn(){
    if(bookerDT == ''){
        bookerDT = baseFn.rpDataTables('.booking_list',{
            ajUrl:baseUrl.base+baseUrl.booking+'selectBookingPageList',
            ajDataSrc:"results.rows",
            ajData:bookerDTdata,
            service:true,
            select:true,
            scrollY:windowOffsetData.tableHeight(),
            ajType:'get',
            autoWidth:false,
            sessionPageKey:'bookingListDTFn',
            columns:[
                { "data": "patientName",width:'18%',defaultContent:'',className:'imgpwrap img2p',render:function(data,type,row, meta){
                    var _img=baseUrl.patientImg
                    if(baseFn.notNull(row.patientImg)){
                        _img = row.patientImg
                    }
                    // return '<img class="imgwrap" src="' + isNull(row.serviceImg, 4) + '">\
                    return '<div class="datatable_img_div" data-vals="'+_img+'" style="background-image:url('+_img+')"></div>\
                            <div class="pwrap bookinglist_base">\
                                <span>'+data+'</span>\
                                <span>'+(baseFn.notNull(row.patientBirthday)?row.patientBirthday:'年龄未知')+'</span>\
                                <span>'+(baseFn.notNull(row.userPhone)?baseFn.getHidePhoneStr(row.userPhone):'手机号未知')+'</span>\
                            </div>'
                    }},
                { "data": "subclinicName",defaultContent:'',width:'10%'},
                { "data": "doctorName",defaultContent:'无',width:'10%'},
                { "data": "bookingType",defaultContent:'无',width: '10%',render:function(data,type,row, meta){
                    if(data == 0){
                        return '调理身体'
                    }else{
                        return '预防保健'
                    }
                }},
                { "data": "isAdd",defaultContent:'无',width: '10%',render:function(data,type,row,meta){
                    if(data == 1 && row.bookingType == 0){
                        return '新治疗'
                    }else if(row.bookingType == 1){
                        return '--'
                    }else{
                        return '继续上次治疗'
                    }
                }},
                { "data": "bookingTime",defaultContent:'无',width: '13%',render:function(data,type,row, meta){
                        var dateArr = data.split(" ");
                        if (dateArr < 2) {
                            return data;
                        }
                        return '<div class="" style="padding-top:0;line-height: 20px">\
                            <div style="font-size: 14px;color: black;font-weight: 800">'+dateArr[0]+'</div>\
                            <div style="font-size: 14px;color: black;font-weight: 800">'+baseFn.getDateWeek(data)+'&nbsp;'+dateArr[1]+'</div>\
                        </div>';
                    }},
                { "data": "bookingSource",defaultContent:'无',width: '8%',render:function(data,type,row,meta){
                    if(data == 0){
                        return '微信'
                    }else
                    if(data == 1){
                        return '后台'
                    }else{
                        return '未知'
                    }

                }},
                { "data": "bookingDesc",defaultContent:'无',width: '13%'},
                { "data": null,defaultContent:'无',width: '20%',className:"center td2p", render:function(data,type,row, meta){
                    //状态:0:待服务;1:已超时;2:调理中;3:待支付;4:已完成;5:取消
                        if(row.bookingStatus == 0 ){
                            //待服务
                            //权限管理 11 接诊/继续/更改/取消预约操作
                            if(baseFn.getPower(11)){
                                return '<button type="button" class="datatablebtn datatablebtnGray" data-vals="'+data+'" onclick="square(this,0,11)" rel="true">取消</button>\
                                <button type="button" class="datatablebtn datatablebtnRed" data-vals="'+data+'" onclick="square(this,0,11)" >更改</button>\
                                <a class="datatablebtn" onclick="square(this,0,11)" href="javascript:void(0)">接诊</a>'
                            }else{
                                return '<button type="button" class="datatablebtn datatablebtnGray" data-vals="'+data+'" onclick="cancelBtn(this)" rel="true">取消</button>\
                                <button type="button" class="datatablebtn datatablebtnRed" data-vals="'+data+'" onclick="updateBtn(this)" >更改</button>\
                                <a class="datatablebtn" onclick="square(this,2)" href="javascript:void(0)" data-vals="'+row.bookingId+','+row.userId+','+row.userPhone+'" rel="true">接诊</a>'
                            }
                        }else if(row.bookingStatus == 3){
                            //待支付
                            //权限管理 48 待付款预约单的结算/取消操作
                            if(baseFn.getPower(48)){
                                return '\
                                <button type="button" class="datatablebtn datatablebtnGray" data-vals="'+data+'" onclick="square(this,0,48)">取消</button>\
                                <button class="datatablebtn" onclick="square(this,0,48)" data-vals="'+data+'">结账</button>';
                            }else{
                                return '\
                                <button type="button" class="datatablebtn datatablebtnGray" data-vals="'+data+'" onclick="cancelBtn(this)">取消</button>\
                                <button class="datatablebtn" data-vals="'+data+'" onclick="square(this,1)">结账</button>';
                            }
                        }else if(row.bookingStatus == 1){
                            //已超时
                            //权限管理 11 接诊/继续/更改/取消预约操作
                            if(baseFn.getPower(11)){
                                return '<button type="button" class="datatablebtn datatablebtnGray" data-vals="'+data+'" onclick="square(this,0,11)" rel="true">取消</button>\
                                <button type="button" class="datatablebtn datatablebtnRed" data-vals="'+data+'" onclick="square(this,0,11)" >更改</button>\
                                <a class="datatablebtn" onclick="square(this,0,11)" href="javascript:void(0)">接诊</a>'
                            }else{
                                return '<button type="button" class="datatablebtn datatablebtnGray" data-vals="'+data+'" onclick="cancelBtn(this)">取消</button>\
                                <button type="button" class="datatablebtn datatablebtnRed" data-vals="'+data+'" onclick="updateBtn(this)" >更改</button>\
                                <a class="datatablebtn" onclick="square(this,2)" href="javascript:void(0)" data-vals="'+row.bookingId+','+row.userId+','+row.userPhone+'">接诊</a>'
                            }
                        }else if(row.bookingStatus == 6){
                            //已接诊
                            //权限管理 11 接诊/继续/更改/取消预约操作
                            if(baseFn.getPower(11)){
                                return '\
                                <button type="button" class="datatablebtn datatablebtnGray" data-vals="'+data+'" onclick="square(this,0,11)" rel="true">取消</button>\
                                <button type="button" class="datatablebtn" data-vals="'+data+'" onclick="square(this,0,11)">继续</button>'
                            }else{
                                var _patient = ''
                                if(baseFn.notNull(row.patientId)){
                                    _patient = '&patientId='+row.patientId
                                }
                                return '\
                                <button type="button" class="datatablebtn datatablebtnGray" data-vals="'+data+'" onclick="cancelBtn(this)" rel="true">取消</button>\
                                <a class="datatablebtn" href="'+baseUrl.base+'order/gotoFastOrder?bookingId='+row.bookingId+'&userId='+row.userId+'&subclinicId='+row.subclinicId+'&doctorId='+row.doctorId+_patient+'" data-vals="'+data+'">继续</a>';
                            }
                        }else if(row.bookingStatus == 5){
                            //已取消
                            var _txt = '用户已取消'
                            if(row.cancelType == 1){
                                _txt = '用户已取消'
                            }else if(row.cancelType == 2){
                                _txt = '商家已取消'
                            }else if(row.cancelType == 3){
                                _txt = '超时'
                            }else if(row.cancelType == 4){
                                _txt = '计划变更'
                            }else if(row.cancelType == 5){
                                _txt = '信息填写错误'
                            }else if(row.cancelType == 6){
                                _txt = '重复预约'
                            }else if(row.cancelType == 7){
                                _txt = '预期的不一致'
                            }else if(row.cancelType == 8){
                                _txt = '其他'
                            }
                            if(!baseFn.notNull(row.cancelTime)){
                                row.cancelTime = '无'
                            }
                            return '<p>'+_txt+'</p>\
                                    <p>取消时间：'+row.cancelTime+'</p>';
                        }else if(row.bookingStatus == 4){
                            //已完成
                            if (row.treatmentState == 1) {
                                return '<p>已完成</p>';
                            } else {
                                var _patient = ''
                                if(baseFn.notNull(row.patientId)){
                                    data.patientId = row.patientId;
                                }
                                if(baseFn.getPower(83)){
                                    return '\
                                    <button type="button" href="javascript:void(0)" class="datatablebtn" data-vals="'+data+'" onclick="square(this,0,83)">完善病历</button>'
                                }else{
                                    return '\
                                    <a class="datatablebtn" href="javascript:void(0)" data-vals="'+data+'"  onclick="square(this,3,83)">完善病历</a>';
                                }
                            }
                        }else if(row.bookingStatus == 2){
                            //调理中
                            return '<p>调理中</p>'
                        }
                    }}
            ],
            initComplete:function(){
            },
            drawCallback: function( settings ) {
                //图片初始化
                $('.datatable_img_div').each(function(ids,val){
                    baseFn.imgSize({
                        src: $(val).data('vals'),
                        hFn: function(res) {
                            res.dom.css({'background-size':'auto 100%'})
                        },
                        wFn: function(res) {
                            res.dom.css({'background-size':'100% auto'})
                        },
                        ratio: 1,
                        otherData: {
                            dom:$(val)
                        }
                    })
                })

            }
        })
    }else{
        var _data = getListDatas();
        baseFn.objDelElm(bookerDTdata,'limit')
        for(var i in _data){
            bookerDTdata[i] = _data[i]
        }
        bookerDT.ajax.reload();
    }
}

//结账跳转 //接诊跳转
function square(e,type,power){
    var _tr = $(e).parents('tr')
    var _data = bookerDT.row(_tr).data()
    if(type == 1){
        //结账
        baseFn.goPath('gotoFastOrder',{bookingId:_data.bookingId,userId:_data.userId,subclinicId:_data.subclinicId,doctorId:_data.doctorId,patientId:_data.patientId,orderId:_data.orderId})
    }else if(type == 2){
        //接诊
        baseFn.goPath('gotoFastOrder',{bookingId:_data.bookingId,userId:_data.userId})
    }else if(type == 3){
        // 完善病历
        baseFn.goPath('gotoFastOrder',{bookingId:_data.bookingId,userId:_data.userId,subclinicId:_data.subclinicId,doctorId:_data.doctorId,patientId:_data.patientId,orderId:_data.orderId,bookingStatus:_data.bookingStatus,treatmentState:_data.treatmentState})
    }else if(type == 0){
        //权限管理 11 接诊/继续/更改/取消预约操作 48 待付款预约单的结算/取消操作
        if(baseFn.getPower(power)){
            baseFn.infoDialog('您没有权限使用功能！')
        }
    }
}

//取消预约
function cancelBtn(e){
    var _tr = $(e).parents('tr');
    var _data=bookerDT.row(_tr).data();
    var bookingId = _data.bookingId;
    var homecareD = baseFn.dialog({
        title:'取消预约',
        width:'13rem',
        height:"3rem",
        content:'是否确认取消',
        ok:function(){
            $.ajax({
                type:"POST",
                url:baseUrl.base+"booking/cancelBooking",
                data:{
                    bookingId:bookingId,
                },
                success:function(res){
                    if(res.code == 0){
                        //alert("取消预约成功!");
                        baseFn.infoDialog('取消预约成功!')
                        bookerDT.rows(_tr).remove().draw(true);
                        getKBDatas();//获取预约看板
                        getbesInfoDatas();
                    }else{
                        baseFn.infoDialog(res.msg)
                    }
                }
            });

        },
        cancel:true ,
        cancelValue: "取消",
    });
}
//更改预约
function updateBtn(e){
    var _tr = $(e).parents('tr');
    var _data=bookerDT.row(_tr).data();
    DocData.bookingInfo.isAdd=''
    DocData.bookingInfo.bookingType=''
    baseFn.$get({
        url:"booking/selectBookingInfo",
        data:{bookingId:_data.bookingId},
        calFn:function(res){
            var bookingDate = baseFn.timestampToTime(res.bookingTime);
            var _bookingTime = bookingDate.substring(0,bookingDate.length-3);
            res.bookingTime = _bookingTime
            DocData.bookingInfo=res
            DocData.initAddBespeak({
                edit:true,
                update:true,
                userName:res.userName,
                userPhone:res.userPhone,
                userPhones:res.userPhones,
                bookingTime:_bookingTime,
                subclinicId:res.subclinicId,
                doctorId:res.doctorId,
                doctorName:res.doctorName,
                bookingDesc:res.bookingDesc,
                bookingId:res.bookingId,
                userId:res.userId
            })
            initPatientListFn(DocData.bookingInfo)
        }
    })
}
//取消订单
function cancelOrder(e){
    var _tr = $(e).parents('tr');
    var _data=bookerDT.row(_tr).data();
    var bookingId = _data.bookingId;
    $.ajax({
        type:"POST",
        url:"",
        data:{
            'bookingId':bookingId,
        },
        success:function(result){
            if(result.code == 0){
                alert('取消订单成功');
                bookerDT.rows(_tr).remove().draw(true);
            }
        }
    })
}
/*预约列表 */
/* 预约看板 */
//预约看板搜索函数
function getKBDatas(){
    var _searchData = {
        bookingDate:'',
        // subclinicId:$('.js_kbsearch_subclinic').val(),
        subclinicId:SessionData.powerSub?SessionData.powerSub:$('.js_kbsearch_subclinic').val(),//权限管理 45 门店是否是全部,
        bookingType:$('.js_kbsearch_type').val()
    }
    if($.trim($('#bespeak_change_time').val()) == ''){
        $('.bespeak_change_look_list_ul.days>.bespeak_change_look_li').each(function () {
            if ($(this).hasClass("addBlueActive")) {
                if ($(this).attr("id") == "day1") { // 今天
                    _searchData.bookingDate = getNowFormatDate();
                } else if ($(this).attr("id") == "day2") { // 明天
                    _searchData.bookingDate = getNextFormatDate();
                } else if ($(this).attr("id") == "day3") { // 后天
                    _searchData.bookingDate = getNextNFormatDate(2);
                }
            }
        });
    }else{
        _searchData.bookingDate = $('#bespeak_change_time').val()
    }
    getBespeakingList(_searchData);
    // return _searchData

}
//看板-日期
baseFn.dateTimePick('#bespeak_change_time',{
    yearStart: 2000,     //设置最小年份
    yearEnd: 2050,        //设置最大年份
    todayButton: false,    //关闭选择今天按钮
    maxDate:false,
    onSelectDate: function () {
        $('.bespeak_change_look_list_ul>.bespeak_change_look_li').removeClass('addBlueActive');
        getKBDatas()
    }
})
//看板-预约类型
$('.js_kbsearch_type').on('change',function(){
    getKBDatas()
})
//天按钮
$('.bespeak_change_look_list_ul>.bespeak_change_look_li').on('click', function () {
    $(this).addClass('addBlueActive').siblings().removeClass('addBlueActive');
        $("#bespeak_change_time").val("");
        $('#bespeak_change_look>tbody').find('tr').remove();
        getKBDatas()
})
//预约看板渲染函数
function getBespeakingList(datas) {//获取预约看板
    $.session.set('selectDoctorGroupBookingList',JSON.stringify(datas));

    $.ajax({
        type: "GET",
        url: baseUrl.base + "booking/selectDoctorGroupBookingList",
        data: datas,
        success: function (res) {
            if (res.code == 0){
                var $table= $('#bespeak_change_look')
                $('#bespeak_change_look>tbody').empty();
                $('#bespeak_change_look>thead').find("th:not('.doctorName')").remove();
                var tableList = res.results.bookingList;//预约信息列表
                var titList = res.results.subclinicInfo;//门店信息
                var _curhour = new Date().getHours()// 获取当前时间;
                var _startTime=Number(titList.subclinicStartTime),_endTime=Number(titList.subclinicEndTime),_startDateTamp = Date.parse(datas.bookingDate + ' ' + titList.subclinicStartTime+':00'),_endDateTamp=Date.parse(datas.bookingDate + ' ' + titList.subclinicStartTime+':00'),_curTamp=Date.parse(new Date())
                //渲染表头时间线
                for(var i=_startTime;i<_endTime;i++){
                    var _thHtml='<th value="' + baseFn.formatDate(i) + '">' + baseFn.formatDate(i) + ':00</th>';
                    $table.find('thead>tr').append(_thHtml)
                }
                //渲染表格
                for(var j=0;j<tableList.length;j++){
                    //渲染行
                    var _tr = $('<tr data-info="'+ tableList[j].subclinicId +',' + tableList[j].doctorId +'">\
                        <td value="0"  class="doctorName" style="text-align:left;padding-left: 0.5rem;background-color: #fff;" rel="' + tableList[j].doctorId + '">' + tableList[j].doctorName + '</td>\</tr>')
                    $table.find('tbody').append(_tr)
                        for(var k=_startTime;k<_endTime;k++){
                            //渲染列
                            var _td = $('<td data-info="'+ tableList[j].subclinicId +',' + tableList[j].doctorId +'" value="' + datas.bookingDate+' ' + baseFn.formatDate(k) + '" rel="'+k+'"></td>');
                            $(_tr).append(_td);
                            /* */
                            // tableList[j].startTime = 0
                            // tableList[j].endTime = 24
                            var _typeSource ={
                                _tempk:Date.parse(baseFn.getOSTime(datas.bookingDate + ' ' + baseFn.formatDate(k) +':00')),//表格时间
                                _curTamp:Date.parse(new Date()),//当前时间
                                _curTamp:new Date().getTime(),//当前时间
                                offDay:(tableList[j].offDay != 0), //true 休息
                                iswork:(tableList[j].isWork == 0),//true 工作
                                hasChildlist:(tableList[j].childList != null && tableList[j].childList.length != 0),//医生是否有预约单列表
                                _beginDoctorWorkTime:Date.parse(baseFn.getOSTime(datas.bookingDate + ' ' + baseFn.formatDate(tableList[j].startTime) +':00')),
                                _endDoctorWorkTime:Date.parse(baseFn.getOSTime(datas.bookingDate + ' ' + baseFn.formatDate(tableList[j].endTime) +':00')),
                                _tdType:0,
                                _td:_td,
                                name:tableList[j].doctorName,
                                _tdTypeChange:function(type){
                                    var _td = this._td,_type=this._tdType
                                    switch(type){
                                        case 1:
                                            //未到可接诊时间//超过接诊时间
                                            $(_td).html('未营业');
                                        break;
                                        case 2:
                                            //休息
                                            $(_td).html('休');
                                        break;
                                        case 3:
                                            //不接诊
                                            $(_td).html('不接诊');
                                        break;
                                        case 4:
                                            //可预约但超时
                                            $(_td).addClass('addIllBgc');
                                        break;
                                        case 5:
                                            //可预约未超时 无任何明细
                                            $(_td).addClass('addIllPeople');
                                            $(_td).addClass('js_addbespeak');
                                        break;
                                        case 6:
                                            //可预约未超时 已开单
                                            $(_td).addClass('tableNewBtnBlue');
                                        break;
                                        case 7:
                                            //可预约未超时 已预约
                                            $(_td).addClass('tableChangeRed');
                                        break;
                                        case 8:
                                            //可预约未超时 已超时
                                            $(_td).addClass('tableChangeinit');
                                        break;

                                    }
                                }
                            }
                            //1
                            //未到接诊时间 医生开始时间 > td时间
                            //超过接诊时间 医生结束时间 < td时间
                            //超时 当前时间 > td时间 && td时间 < 医生开始时间 && 医生结束时间 > td时间
                            //可预约 当前时间 < td时间 && td时间 < 医生开始时间 && 医生结束时间 > td时间
                            //休息 offDay != 0
                            //不接诊 iswork == 0
                            //2
                            //已预约
                            //已接诊
                            //已取消
                            //已完成
                            //已过时
                            if(_typeSource.offDay){//休息
                                _typeSource._tdTypeChange(2)
                            }else if(_typeSource.iswork){//不接诊
                                _typeSource._tdTypeChange(3)
                            }else if(_typeSource._tempk<_typeSource._beginDoctorWorkTime){//未到可接诊时间
                                _typeSource._tdTypeChange(1)
                            }else if(_typeSource._tempk>=_typeSource._endDoctorWorkTime){//超过接诊时间
                                _typeSource._tdTypeChange(1)
                            }else if(_typeSource._tempk >= _typeSource._beginDoctorWorkTime && _typeSource._tempk < _typeSource._endDoctorWorkTime && (_typeSource._tempk <_typeSource._curTamp || baseFn.getPower(10))){
                                if(_typeSource.hasChildlist){
                                    var bookingTime = _typeSource._td.attr('rel')
                                    var _list = tableList[j].childList.filter(function(val){
                                        return new Date(val.bookingTime).getHours() == bookingTime && val.bookingStatus != 5
                                    })
                                    if(_list && _list.length !=0){
                                        var bookingStatus = _list[0].bookingStatus,_txt='';
                                        if (bookingStatus == 6 || bookingStatus == 3 || bookingStatus == 4) {//已开单
                                            _txt = _list[0].userName
                                            _typeSource._tdTypeChange(6)
                                        }else if (bookingStatus == 0 || bookingStatus == 2) {//已预约
                                            _txt = _list[0].userName
                                            _typeSource._tdTypeChange(7)
                                        }else if (bookingStatus == 1) {//已超时
                                            _txt = _list[0].userName
                                            _typeSource._tdTypeChange(8)
                                        }else if (bookingStatus == 5) {
                                            _typeSource._tdTypeChange(4)
                                        }else{

                                        }
                                        $(_typeSource._td).text(_txt)
                                    }else{
                                        _typeSource._tdTypeChange(4)
                                    }
                                }else{
                                    _typeSource._tdTypeChange(4)
                                }

                            }else if(_typeSource._tempk >= _typeSource._beginDoctorWorkTime && _typeSource._tempk < _typeSource._endDoctorWorkTime && _typeSource._tempk >= _typeSource._curTamp){
                                if(_typeSource.hasChildlist){
                                    var bookingTime = _typeSource._td.attr('rel')
                                    var _list = tableList[j].childList.filter(function(val){
                                        return new Date(val.bookingTime).getHours() == bookingTime && val.bookingStatus != 5
                                    })
                                    if(_list && _list.length !=0){
                                        var bookingStatus = _list[0].bookingStatus,_txt='';
                                        if (bookingStatus == 6 || bookingStatus == 3 || bookingStatus == 4) {//已开单
                                            _txt = _list[0].userName
                                            _typeSource._tdTypeChange(6)
                                        }else if (bookingStatus == 0 || bookingStatus == 2) {//已预约
                                            _txt = _list[0].userName
                                            _typeSource._tdTypeChange(7)
                                        }else if (bookingStatus == 1) {//已超时
                                            _txt = _list[0].userName
                                            _typeSource._tdTypeChange(8)
                                        }else if (bookingStatus == 5) {
                                            _typeSource._tdTypeChange(5)
                                        }
                                        $(_typeSource._td).text(_txt)
                                    }else{
                                        _typeSource._tdTypeChange(5)
                                    }
                                }else{
                                    _typeSource._tdTypeChange(5)
                                }

                            }
                            /*
                                //小于时间为超时td
                                var _tempk = Date.parse(datas.bookingDate + ' ' + k +':00')

                                if(_tempk<_curTamp){
                                    $(_td).addClass('addIllBgc');
                                }else if(baseFn.getPower(10)){
                                    //权限控制 预约管理 新增预约
                                    $(_td).addClass('addIllBgc');
                                }else{
                                    $(_td).addClass('addIllPeople');
                                    $(_td).addClass('js_addbespeak');
                                }
                                tableList[j].startTime = 13
                                tableList[j].endTime = 20
                                var _beginDoctorWorkTime = Date.parse(datas.bookingDate + ' ' + tableList[j].startTime +':00'),_endDoctorWorkTime = Date.parse(datas.bookingDate + ' ' + tableList[j].endTime +':00')
                                if(_tempk<_beginDoctorWorkTime){
                                    $(_td).removeClass('js_addbespeak');
                                    $(_td).removeClass('addIllPeople');
                                    $(_td).html('未到可接诊时间')
                                }
                                if(_tempk>_endDoctorWorkTime){
                                    $(_td).removeClass('js_addbespeak');
                                    $(_td).removeClass('addIllPeople');
                                    $(_td).html('超过可接诊时间')
                                }
                            */
                        }
                    /*
                    var _tds = $(_tr).find("td:not('.doctorName')")
                    if(tableList[j].offDay == 0){
                        if(tableList[j].childList != null){
                            for(var k=0;k<tableList[j].childList.length;k++){
                                var _childInfo=tableList[j].childList[k],bookingStatus=_childInfo.bookingStatus,bookingTime=new Date(_childInfo.bookingTime).getHours();
                                _tds.each(function(m,n){

                                    if(bookingTime == $(n).attr('rel') && !$(n).hasClass('tableChangeRed') && !$(n).hasClass('tableNewBtnBlue') && !$(n).hasClass('tableChangeinit')){
                                        $(n).removeClass('addIllPeople');
                                        $(n).removeClass('js_addbespeak');
                                        if (bookingStatus == 6 || bookingStatus == 3 || bookingStatus == 4) {//已开单
                                            _txt = _childInfo.userName
                                            $(n).addClass('tableNewBtnBlue');
                                        }
                                        if (bookingStatus == 0 || bookingStatus == 2) {//已预约
                                            _txt = _childInfo.userName
                                            $(n).addClass('tableChangeRed');
                                        }
                                        if (bookingStatus == 1) {//已超时
                                            _txt = _childInfo.userName
                                            $(n).addClass('tableChangeinit');
                                        }
                                        if (bookingStatus == 5) {
                                            $(n).removeClass('tableNewBtnBlue');
                                            $(n).removeClass('tableChangeRed');
                                            _txt = ''
                                            var _tempRel = Date.parse(datas.bookingDate + ' ' + $(n).attr('rel') +':00')
                                            if(baseFn.getPower(10)){
                                                //权限控制 预约管理 新增预约
                                                $(_td).addClass('addIllBgc');
                                            }else if(_tempRel >= _curTamp){
                                                $(n).addClass('addIllPeople');
                                                $(n).addClass('js_addbespeak');
                                            }
                                        }
                                        $(n).text(_txt);
                                    }
                                })
                            }
                        }else{
                            // _tds.each(function(x,y){
                            //     $(y).text('无数据').css("background-color",'#fff');
                            // })
                        }
                    }else{
                        _tds.each(function(x,y){
                            $(y).removeClass('addIllPeople');
                            $(y).removeClass('js_addbespeak');
                            $(y).text('休').css("background-color",'#fff');
                        })
                    }

                    if(tableList[j].isWork != 0){}else{
                        //接诊未接诊
                        _tds.each(function(w,b){
                            $(b).removeClass('addIllPeople');
                            $(b).removeClass('js_addbespeak');
                            $(b).removeClass('tableChangeRed');
                            $(b).removeClass('tableNewBtnBlue');
                            $(b).removeClass('tableChangeinit');
                            $(b).text('不接诊').css("background-color",'#fff');
                        })
                    }
                    */
                }
                // //增添新增功能
                // var _alltds = $table.find('tbody td').not($('.doctorName'));
                // _alltds.each(function (index, obj){
                //     var _info=$(obj).parent('tr').data('info')
                //     $(obj).data('info',_info)
                //     if($(obj).text() == ''){
                //         $(obj).addClass('addIllPeople');
                //         $(obj).addClass('js_addbespeak');
                //     }
                //     if($(obj).attr('rel')< _curhour){
                //         $(obj).removeClass('addIllPeople');
                //         $(obj).removeClass('js_addbespeak');
                //         $(obj).addClass('addIllBgc');
                //     }
                // })
            }
        }
    })
}
/* 预约看板 */
/*预约信息*/
function getbesInfoDatas(flush, fromInput){
    var _weeks = DocData.timecompat() ;
    if (flush && baseFn.notNull($.session.get('selectBookingWeekList'))){
        var data = JSON.parse($.session.get('selectBookingWeekList'))
        if (baseFn.notNull(data.startDate)){
            _weeks.weekStart = data.startDate;
            $("#startDate_stat").val(data.startDate);
        }
        if (baseFn.notNull(data.endDate)){
            _weeks.weekEnd = data.endDate;
            $("#endDate_stat").val(data.endDate);
        }
    }

    var _searchData = {
        startDate: fromInput ? $("#startDate_stat").val() : _weeks.weekStart,
        endDate : fromInput ? $("#endDate_stat").val() : _weeks.weekEnd,
        subclinicId:SessionData.powerSub?SessionData.powerSub:$('#subclinic_info').val(),//权限管理 45 门店是否是全部,
        bookingType:$('#status_info').val(),
        userPhone:$('.info_search').siblings('input.bespeak_search_input').val(),
        fromInput: fromInput ? 1 : 0
    }
    getStatInfoList(_searchData);
}
//信息-预约类型
$('#status_info').on('change',function(){
    getbesInfoDatas()
})
$('.weekbtn').on('click',function(){
    DocData.baseWeek += Number($(this).attr('rel'))
    getbesInfoDatas()
    if (baseFn.notNull($.session.get('selectBookingWeekList'))) {
        var data = JSON.parse($.session.get('selectBookingWeekList'))
        $("#startDate_stat").val(data.startDate);
        $("#endDate_stat").val(data.endDate);
    }
})
$('.info_search').on('click',function(){
    getbesInfoDatas()
})
function getStatInfoList(opts) {
    $.session.set('selectBookingWeekList',JSON.stringify(opts));

    $.ajax({
        type: "GET",
        url: baseUrl.base + "booking/selectBookingWeekList",
        data:opts,
        success: function (data) {
            if (data.code == 0) {
                $('#bespeak_stat_info>tbody').empty();
                $('#bespeak_stat_info>thead').find("th:not('.doctorName')").remove();
                var tableList = data.results.bookingList;
                var subInfo = data.results.subclinicInfo;
                var startTime = parseInt(subInfo.subclinicStartTime);
                var endTime = parseInt(subInfo.subclinicEndTime);

                for (var j = startTime; j < endTime; j++) {
                    var titHtml = '<th value="' + j + '">' + j + ':00</th>';
                    $('#bespeak_stat_info>thead>tr').append(titHtml);
                }

                for (var i = 0; i < tableList.length; i++) {
                    var trData = tableList[i];
                    var weekNum = trData.weekNum;
                    var todayStr = trData.today;
                    var amCount = trData.amCount;
                    var pmCount = trData.pmCount;

                    var html = ' <tr>\
                        <td value="0"  class="doctorName" style="text-align:left;padding-left: 0.5rem;background-color: #fff;" rel="' + weekNum + '" data-date="'+todayStr+'">' + weekNum + (!opts.fromInput ? '<br> ' + todayStr : '')+ '</td>\
                        <td>上午&nbsp;' + amCount + '<br>下午&nbsp;' + pmCount + '</td>';

                    for (var j = startTime; j < endTime; j++) {
                        var totalCount = 0;
                        var tdToday='',tdHours=''
                        for (var child in trData.childList) {
                            var childData = trData.childList[child];
                            if (childData.hours == j) {
                                totalCount++;
                                tdHours=childData.hours
                                tdToday=childData.today
                            }
                        }
                        var tdHtml = ''
                        if(totalCount != 0){
                            tdHtml = '<td data-date="'+tdToday+' '+tdHours+'"' + (!opts.fromInput ? ' onclick="findDetail(this)"' : '') +'>共' + totalCount + '人</td>';
                        }else{
                            tdHtml = '<td value="">无人预约</td>';
                        }
                        html += tdHtml;
                    }
                    html += '</tr>';

                    // alert("html: " + html);

                    $('#bespeak_stat_info>tbody').append(html);
                }
                var tr = $('#bespeak_stat_info>tbody>tr');
                for (var j = 0; j < tableList.length; j++) {
                    var trData = tableList[j];
                    var weekNum = trData.weekNum;
                    // var doctorId = tableList[j].doctorId;
                    var childList = tableList[j].childList;
                    // var userName = null;
                    // var bookingStatus = null;
                    // var timer = null;

                    // for (var i = 0; i < childList.length; i++) {
                    //     userName = childList[i].userName;
                    //     bookingStatus = childList[i].bookingStatus;
                    //     timer = new Date(timestampToTime(childList[i].bookingTime));//2018-04-4 10:3:59
                    //     timer = timer.getHours();
                    //     $(tr).each(function (index, obj) {
                    //         if ($(obj).find('td').eq(0).attr('rel') == doctorId) {
                    //             $(obj).find('td').each(function (x, f) {
                    //                 if ($(f).not($('.doctorName')).attr('value') == timer) {
                    //                     $(f).text(userName);
                    //                     if (bookingStatus == 6 || bookingStatus == 3 || bookingStatus == 4) {//已开单
                    //                         $(f).addClass('tableNewBtnBlue');
                    //                     }
                    //                     if (bookingStatus == 0 || bookingStatus == 2) {//已预约
                    //                         $(f).addClass('tableChangeRed');
                    //                     }
                    //                     if (bookingStatus == 1) {//已超时
                    //                         $(f).addClass('tableChangeinit');
                    //                     }
                    //                     if (bookingStatus == 5) {
                    //                         $(f).text('');
                    //                     }
                    //                 }
                    //             })
                    //         }
                    //     })
                    // }
                }
            }
        }
    });
}
function findDetail(e){
    var _e = e,_tempDate=$(_e).data('date')
    // var _endDate= _tempDate.substring(0,11) + (baseFn.formatDate(Number(_tempDate.substring(11,13))+1))+':00:00'
    var _updatas={
        startTime:_tempDate+':00:00',
        endTime:_tempDate+':59:59'
    }
    if($('#subclinic_info').val() != ''){
        _updatas.subclinicId=$('#subclinic_info').val()
       // _url += '&subclinicId='+$('#subclinic_info').val()
    }
    if($('#status_info').val() != ''){
        _updatas.bookingType=$('#status_info').val()
        //_url += '&bookingStatus='+ $('#status_info').val()
    }
    if($.trim($('.info_search').siblings('input.bespeak_search_input').val()) != ''){
        _updatas.userPhone=$.trim($('.info_search').siblings('input.bespeak_search_input').val())
        //_url += '&userPhone='+ $.trim($('.info_search').siblings('input.bespeak_search_input').val())
    }
    baseFn.goPath('gotoBespeakInfoDetail',_updatas)
    // window.location.href = _url
}
/*预约信息*/
/*预约明细 */
var bookDetailD =''
if(DocData.startTimeD != '' && DocData.endTimeD !=''){
    var _deailInfoData={
        startDate:DocData.startTimeD,
        endDate:DocData.endTimeD
    }
    if(DocData.subclinicId != ''){
        _deailInfoData.subclinicId=DocData.subclinicId
    }
    if(DocData.bookingTypeD != ''){
        _deailInfoData.bookingType=DocData.bookingTypeD
    }
    if(DocData.userPhoneD != ''){
        _deailInfoData.userPhone=DocData.userPhoneD
    }
    bookDetailD = baseFn.rpDataTables('.detail_list',{
        // ajUrl:baseUrl.base+baseUrl.booking+'selectBookingList',
        // ajData:_deailInfoData,
        // ajDataSrc:"results",
        ajUrl:baseUrl.base+baseUrl.booking+'selectBookingPageList',
        ajDataSrc:"results.rows",
        ajData:_deailInfoData,
        service:true,
        select:true,
        scrollY:windowOffsetData.tableHeight(),
        ajType:'get',
        autoWidth:false,
        columns:[
            { "data": "patientName",width:'18%',defaultContent:'',className:'imgpwrap img2p',render:function(data,type,row, meta){
                var _img=baseUrl.patientImg
                if(baseFn.notNull(row.patientImg)){
                    _img = row.patientImg
                }
                // return '<img class="imgwrap" src="' + isNull(row.serviceImg, 4) + '">\
                return '<div class="datatable_img_div" data-vals="'+_img+'" style="background-image:url('+_img+')"></div>\
                        <div class="pwrap">\
                            <span>'+data+'</span>\
                            <span>'+(baseFn.notNull(row.patientBirthday)?row.patientBirthday:'年龄未知')+'</span>\
                        </div>'
                }},
            { "data": "subclinicName",defaultContent:'',width:'10%'},
            { "data": "doctorName",defaultContent:'无',width:'10%'},
            { "data": "bookingType",defaultContent:'无',width: '10%',render:function(data,type,row, meta){
                if(data == 0){
                    return '调理身体'
                }else{
                    return '预防保健'
                }
            }},
            { "data": "isAdd",defaultContent:'无',width: '10%',render:function(data,type,row,meta){
                if(data == 1 && row.bookingType == 0){
                    return '新治疗'
                }else if(row.bookingType == 1){
                    return '--'
                }else{
                    return '继续上次治疗'
                }
            }},
            { "data": "bookingTime",defaultContent:'无',width: '15%',render:function(data,type,row, meta){
                    var dateArr = data.split(" ");
                    if (dateArr < 2) {
                        return data;
                    }
                    return '<div class="" style="padding-top:0;line-height: 20px">\
                        <div>'+dateArr[0]+'</div>\
                        <div>'+baseFn.getDateWeek(data)+'&nbsp;'+dateArr[1]+'</div>\
                    </div>';
                }},
            { "data": "bookingDesc",defaultContent:'无',width: '18%'},
            { "data": 'bookingStatus',defaultContent:'无',width: '20%',className:"center", render:function(data,type,row, meta){
                //状态:0:待服务;1:已超时;2:调理中;3:待支付;4:已完成;5:取消
                if(data == 0){
                    return '待就诊'
                }else if(data == 1){
                    return '已超时'
                }else if(data == 2){
                    return '调理中'
                }else if(data == 3){
                    return '待支付'
                }else if(data == 4){
                    return '已完成'
                }else if(data == 6){
                    return '已接诊'
                }else{
                    //5
                    return '已取消'
                }
            }}
        ],
        initComplete:function(){
        },
        drawCallback: function( settings ) {
            // alert( '表格重绘了' );
        }
    })
}
/*预约明细 */
//门店下拉列表
if($("select#subclinic").length != 0){//如果是预约管理页面就加载
$.ajax({
    type: "GET",
    url: baseUrl.base + baseUrl.subclinic+"selectSubclinicList",
    data: '',
    success: function (result) {
        if (result.code == 0) {
            DocData.subclinicList=result.results
            var _subData=[]
            // $(".subclinic").append("<option class='picker_style' value=0>全部门店</option>")
            for (var i = 0; i < result.results.length; i++) {
                _subData.push({id:result.results[i].subclinicId,text:result.results[i].subclinicName})
            }
            //门店下拉列表 - 预约列表
            baseFn.rpSelect('select#subclinic',{
                datas:_subData,
                selFn:function(){
                    bookingListDTFn()
                },
                calFn:function(){

                    if (baseFn.notNull($.session.get('bespeak_change_list_datas'))){
                        var data = JSON.parse($.session.get('bespeak_change_list_datas'));
                        $('select#subclinic').val(data.subclinicId).trigger('change');
                    }else {
                        if(SessionData.powerSub){
                            //权限管理 45 门店是否是全部
                            $('select#subclinic').val(SessionData.powerSub).trigger('change');
                        }else if(baseFn.notNull(DocData.subclinicId)){
                            $('select#subclinic').val(DocData.subclinicId).trigger('change')
                        }
                    }
                    bookingListDTFn()
                }
            })

            //门店下拉列表 - 预约看板
            baseFn.rpSelect('select#subclinic_kanban',{
                datas:_subData,
                selFn:function(){
                    getKBDatas()
                },
                calFn:function(){
                    if (baseFn.notNull($.session.get('selectDoctorGroupBookingList'))){
                        var data = JSON.parse($.session.get('selectDoctorGroupBookingList'));
                        $('select#subclinic_kanban').val(data.subclinicId).trigger('change');
                    }else {
                        if (SessionData.powerSub) {
                            //权限管理 45 门店是否是全部
                            $('select#subclinic_kanban').val(SessionData.subclinicId).trigger('change');
                        }
                    }
                    getKBDatas();
                }
            })
            //门店下拉列表 - 预约信息（统计）页选择门店下拉框改变
            baseFn.rpSelect('select#subclinic_info',{
                datas:_subData,
                selFn:function(){
                    getbesInfoDatas()
                },
                calFn:function(){
                    if (baseFn.notNull($.session.get('selectBookingWeekList'))){
                        var data = JSON.parse($.session.get('selectBookingWeekList'));
                        $('select#subclinic_info').val(data.subclinicId).trigger('change');
                    }else {
                        if (SessionData.powerSub) {
                            //权限管理 45 门店是否是全部
                            $('select#subclinic_info').val(SessionData.powerSub).trigger('change');
                        }
                    }
                    getbesInfoDatas(true)
                }
            })
            //新增预约弹框
            baseFn.rpSelect('select.js_subclinicId',{
                datas:_subData,
                selFn:function(e){
                    var _upData_ = {
                        subclinicId:e.params.data.id
                    }
                    DocData.bookingInfo.subclinicId = e.params.data.id
                    DocData.bookingInfo.doctorId = ''
                    if(baseFn.notNull($('.js_bookingTime').val())){
                        _upData_.bookingTime = $('.js_bookingTime').val()+':00'
                    }
                    selectDoctor(_upData_)
                    if(baseFn.notNull(DocData.subclinicList) && DocData.subclinicList.length != 0){
                        var _val = e.params.data.id,_acSub=DocData.subclinicList.filter(function(val){
                            return _val == val.subclinicId
                        })[0],_startTime=Number(_acSub.subclinicStartTime),_endTime=Number(_acSub.subclinicEndTime)
                        if(baseFn.notNull($('.js_bookingTime').val())){
                            var _time = Number($('.js_bookingTime').val().substring(11,13))
                            if(_time <_startTime || _time > _endTime){
                                $('.js_bookingTime').val('')
                            }
                        }
                        DocData.bookingTime.allowTimes=[]
                        for(var i=_startTime;i<=_endTime;i++){
                            DocData.bookingTime.allowTimes.push(i+':00')
                        }
                        baseFn.dateTimePick('.js_bookingTime',DocData.bookingTime)
                    }
                },
                calFn:function(){
                    if(SessionData.powerSub){
                        //权限管理 45 门店是否是全部
                        $('select.js_subclinicId').val(SessionData.powerSub).trigger('change');
                        selectDoctor({subclinicId:SessionData.powerSub})
                    }else if(baseFn.notNull(DocData.bookingInfo.subclinicId)){
                        $('select.js_subclinicId').val(DocData.bookingInfo.subclinicId).trigger('change');
                        selectDoctor({subclinicId:DocData.bookingInfo.subclinicId})
                    }
                }
            })
            // var bookingTime = $('.js_bookingTime').val();
            // //新增预约弹框
            // baseFn.rpSelect('select.js_subclinicId',{
            //     width:'26.5%',
            //     datas:_subData,
            //     selFn:function(e){
            //         $.get(baseUrl.base + baseUrl.booking +"selectFreeDoctor",{bookingTime:$('.js_bookingTime').val()+':00',subclinicId:e.params.data.id},function(res){
            //             if(res.code == '0'){
            //                 $('.js_doctorId').find('option').remove()
            //                 if (res.results == null) {
            //                     baseFn.infoDialog('该门店当前时间段暂无推拿师可以预约',function(){},1000)
            //                     $('.js_doctorId').append("<option value=''>请选择推拿师</option>");
            //                 } else {
            //                     for(var x=0;x<res.results.length;x++){
            //                         $('.js_doctorId').append("<option value='" + res.results[x].userId + "'>" + res.results[x].userName + "</option>");
            //                     }
            //                     $('.js_doctorId').val(res.results[0].userId)
            //                 }
            //             }else{
            //                 baseFn.infoDialog(res.msg)
            //             }
            //         },'json')
            //         if(baseFn.notNull(DocData.subclinicList) && DocData.subclinicList.length != 0){
            //             var _val = e.params.data.id,_acSub=DocData.subclinicList.filter(function(val){
            //                 return _val == val.subclinicId
            //             })[0],_startTime=Number(_acSub.subclinicStartTime),_endTime=Number(_acSub.subclinicEndTime)
            //             if(baseFn.notNull($('.js_bookingTime').val())){
            //                 var _time = Number($('.js_bookingTime').val().substring(11,13))
            //                 if(_time <_startTime || _time > _endTime){
            //                     $('.js_bookingTime').val('')
            //                 }
            //             }
            //             DocData.bookingTime.allowTimes=[]
            //             for(var i=_startTime;i<=_endTime;i++){
            //                 DocData.bookingTime.allowTimes.push(i+':00')
            //             }
            //             baseFn.dateTimePick('.js_bookingTime',DocData.bookingTime)
            //         }
            //     },
            //     calFn:function(){
            //         if(SessionData.powerSub){
            //             //权限管理 45 门店是否是全部
            //             $('select.js_subclinicId').val(SessionData.powerSub).trigger('change');
            //         }
            //     }
            // })
            // $('select.js_subclinicId').on('select2:selecting',function(){
            //     bookingTime = $('.js_bookingTime').val();
            //     if(bookingTime == ''){
            //         baseFn.infoDialog('请先选择预约时间')
            //         return false
            //     }
            // })
            // $('select.js_subclinicId').on('change',function(){
            //     $.get(baseUrl.base + baseUrl.booking +"selectFreeDoctor",{bookingTime:$('.js_bookingTime').val()+':00',subclinicId:$(this).val()},function(res){
            //         if(res.code == '0'){
            //             $('.js_doctorId').find('option').remove()
            //             if (res.results == null) {
            //                 baseFn.infoDialog('该门店当前时间段暂无推拿师可以预约',function(){},1000)
            //                 $('.js_doctorId').append("<option value=''>请选择推拿师</option>");
            //             } else {
            //                 for(var x=0;x<res.results.length;x++){
            //                     $('.js_doctorId').append("<option value='" + res.results[x].userId + "'>" + res.results[x].userName + "</option>");
            //                 }
            //                 if(DocData.bookingInfo.doctorId == ''){
            //                     $('.js_doctorId').val(res.results[0].userId)
            //                 }else{
            //                     $('.js_doctorId').val(DocData.bookingInfo.doctorId)
            //                 }

            //             }
            //         }else{
            //             baseFn.infoDialog(res.msg)
            //         }
            //     },'json')
            //     if(baseFn.notNull(DocData.subclinicList) && DocData.subclinicList.length != 0){
            //         var _val = $(this).val(),_acSub=DocData.subclinicList.filter(function(val){
            //             return _val == val.subclinicId
            //         })[0],_startTime=Number(_acSub.subclinicStartTime),_endTime=Number(_acSub.subclinicEndTime)
            //         if(baseFn.notNull($('.js_bookingTime').val())){
            //             var _time = Number($('.js_bookingTime').val().substring(11,13))
            //             if(_time <_startTime || _time > _endTime){
            //                 $('.js_bookingTime').val('')
            //             }
            //         }
            //         DocData.bookingTime.allowTimes=[]
            //         for(var i=_startTime;i<=_endTime;i++){
            //             DocData.bookingTime.allowTimes.push(i+':00')
            //         }
            //         baseFn.dateTimePick('.js_bookingTime',DocData.bookingTime)
            //     }
            // })
        }
    }
});
}
function selectDoctor(data){
    baseFn.$get({
        url:baseUrl.booking +"selectFreeDoctor",
        data:data,
        canNull:true,
        calFn:function(res){
            if(baseFn.notNull(res) && res.length != 0){
                $('.js_doctorId').html('')
                for(var x=0;x<res.length;x++){
                    $('.js_doctorId').append("<option value='" + res[x].userId + "'>" + res[x].userName + "</option>");
                }
                if(baseFn.notNull(DocData.bookingInfo.doctorId)){
                    $('.js_doctorId').val(DocData.bookingInfo.doctorId)
                }else{
                    $('.js_doctorId').val(res[0].userId)
                }
            }else{
                $('.js_doctorId').html('')
                baseFn.infoDialog('该门店当前时间段暂无推拿师可以预约',function(){},1000)
            }
        }
    })
}
// 页面切换逻辑
$('.num1').on('click', function () {
    $.session.set('bespeak_tab','.num1');
    $(this).addClass('bespeak_active').siblings().removeClass('bespeak_active');
    $('#bespeak_list').show();
    $('#bespeak_board').hide();
    $('#bespeak_info').hide();
});
$('.num2').on('click', function () {
    $.session.set('bespeak_tab','.num2');
    $(this).addClass('bespeak_active').siblings().removeClass('bespeak_active');
    $('#bespeak_list').hide();
    $('#bespeak_board').show();
    $('#bespeak_info').hide();
});
$('.num3').on('click', function () {
    $.session.set('bespeak_tab','.num3');
    $(this).addClass('bespeak_active').siblings().removeClass('bespeak_active');
    $('#bespeak_list').hide();
    $('#bespeak_board').hide();
    $('#bespeak_info').show();
})
if(DocData.startTimeD != '' && DocData.endTimeD !=''){
    $('.num1').off('click')
    $('.num2').off('click')
    $('.num3').off('click')
}

if(baseFn.notNull(baseFn.getQueryString('num'))){
    // $('.num'+baseFn.getQueryString('num')).trigger('click')
}
if(baseFn.notNull(baseFn.getQueryString('home'))){
    $('.Baby_Healthy_home_right_bespeak_search .js_addbespeak').trigger('click')
}
//表格自适应
window.onresize = function(){
    windowOffsetData.refresh();
    $(bookerDT.table().body()).parents('.dataTables_scrollBody').css('max-height',windowOffsetData.tableHeight());
    bookerDT.draw(false);
}

//顶部tab页面的缓存
if (baseFn.notNull($.session.get('bespeak_tab'))){
    $($.session.get('bespeak_tab')).click();
}else {
    //权限管理
    $($('.Baby_Healthy_home_right_top_list>li:not(".hidden")')[0]).trigger('click')

}
